﻿using AutoMapper;
using MediatR;
using S.Archives.Domain.S.ArchivesDto;
using S.Archives.Infrstructre.InterFace;
using S.Archives.Read.Api.Application.Command;
using S.Common.Enums.Archives;

namespace S.Archives.Read.Api.Application.CommandHandlers
{
    /// <summary>
    /// 获取可以销售的耳号
    /// </summary>
    public class SalesEarTagSelCommandHandler : IRequestHandler<SalesEarTagSelCommand, List<EnumStringDto>>
    {
        private readonly ISheepFileRepository sheepFileRepository;
        private readonly IMapper mapper;
        public SalesEarTagSelCommandHandler(ISheepFileRepository sheepFileRepository, IMapper mapper)
        {
            this.sheepFileRepository = sheepFileRepository;
            this.mapper = mapper;
        }

        public async Task<List<EnumStringDto>> Handle(SalesEarTagSelCommand request, CancellationToken cancellationToken)
        {
            var list = sheepFileRepository.GetAllAsync().Result;
            if (request.id > 0)
            {
                list = list.Where(x => x.FileType == request.id).ToList();
            }
            //活着在场的羊
            list = list.Where(x => x.WanderReproductiveState != (WanderReproductiveStateEnum)9  &&x.PresenceState==2 || x.WanderReproductiveState!= (WanderReproductiveStateEnum)7).ToList();
            List<EnumStringDto> enumDto = new List<EnumStringDto>();
            enumDto = mapper.Map<List<EnumStringDto>>(list);
            return enumDto;
        }
    }
}
